﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

namespace ClassLibrary6
{
    public class BacklogPage : Page
    {

        public BacklogPage(OpenQA.Selenium.IWebDriver driver)
        {
             base.driver = driver;
        }

        internal void openAddBacklogForm()
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until((d) => { return d.FindElement(By.LinkText("Add item")); });

            IWebElement addButton = driver.FindElement(By.LinkText("Add item"));
            addButton.Click();
        }

        internal void addNewItem(string itemTitle, string itemDescription)
        {
            openAddBacklogForm();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until((d) => { return d.FindElement(By.Id("item_user_story")); });

            IWebElement itemTitleField = driver.FindElement(By.Id("item_user_story"));
            IWebElement itemDescriptionField = driver.FindElement(By.Id("item_description"));
            IWebElement commit = driver.FindElement(By.Name("commit"));

            itemTitleField.SendKeys(itemTitle);
            itemDescriptionField.SendKeys(itemDescription);
            commit.Click();

        }

        internal void assertItemIsAdded(string itemTitle)
        {
            assertTextPresent(itemTitle);
        }

        internal void removeItem(string p)
        {
            throw new NotImplementedException();
        }

        internal void assertThatItemIsRemoved(string p)
        {
            throw new NotImplementedException();
        }
    }
}
